﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using MyHotel_Common;
using System.Data.SqlClient;

namespace MyHotel_DAO
{
    public class PhanQuyenDAO : DAO
    {
        protected override object createObjectFromDatarow(System.Data.DataRow row)
        {
            PhanQuyen phanQuyen = new PhanQuyen();
            phanQuyen.MaPhanQuyen = int.Parse(row["MaPhanQuyen"].ToString());
            phanQuyen.MaChucVu = int.Parse(row["MaChucVu"].ToString());
            phanQuyen.MaMenu = int.Parse(row["MaMenu"].ToString());

            return phanQuyen;
        }

        public bool xoaPhanQuyen(PhanQuyen phanQuyen)
        {
            string nameProc = "SP_DELETE_PHANQUYEN";
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MAMENU", phanQuyen.MaMenu);
            para[1] = new SqlParameter("@MACV", phanQuyen.MaChucVu);
            return DataProvider.executeStoreProcedureNonQuery(nameProc, para) == 1;
        }

        public bool themPhanQuyen(PhanQuyen phanQuyen)
        {
            string nameProc = "SP_THEMPHANQUYEN";
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MAMN", phanQuyen.MaMenu);
            para[1] = new SqlParameter("@MACV", phanQuyen.MaChucVu);
            return DataProvider.executeStoreProcedureNonQuery(nameProc, para) == 1;
        }
    }
}
